package com.pai4j.netty.server.config.properties;


import com.pai4j.netty.server.common.PropertyLoader;
import lombok.Data;


/**
 redis.host=127.0.0.1
 redis.port=6379
 redis.database=6
 redis.jedis.timeout=5000
 redis.jedis.pool.max-active=100
 redis.jedis.pool.max-wait=-1
 redis.jedis.pool.min-idle=10
 */
@Data
public class RedisConfig {

    private String host;

    private int port;

    private String password;

    private int database;

    private int timeout;

    private int maxActive;

    private int maxWait;

    private int minIdle;

    public static RedisConfig init() {
        RedisConfig redisConfig = new RedisConfig();
        redisConfig.host = PropertyLoader.safeGetProperty("redis.host", String.class);
        redisConfig.port = PropertyLoader.safeGetProperty("redis.port", Integer.class);;
        redisConfig.database = PropertyLoader.safeGetProperty("redis.database", Integer.class);;
        redisConfig.password = PropertyLoader.safeGetProperty("redis.password", String.class, true);;
        redisConfig.timeout = PropertyLoader.safeGetProperty("redis.jedis.timeout", Integer.class);;
        redisConfig.maxActive = PropertyLoader.safeGetProperty("redis.jedis.pool.max-active", Integer.class);;
        redisConfig.maxWait = PropertyLoader.safeGetProperty("redis.jedis.pool.max-wait", Integer.class);;
        redisConfig.minIdle = PropertyLoader.safeGetProperty("redis.jedis.pool.min-idle", Integer.class);;
        return redisConfig;
    }
}
